﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace JCW.Common
{
    /// <summary>
    ///Cookie类
    /// </summary>
    public static class CookieHelper
    {

        ///
        public static string Get(string cookieName)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[cookieName];
            if (cookie != null)
                return cookie.Value;
            else
                return null;
        }

        public static void Set(string cookieName, string cookieValue, int hours)
        {
            HttpCookie cookie = new HttpCookie(cookieName);
            cookie.Value = cookieValue;
            if (hours > 0)
                cookie.Expires = DateTime.Now.AddHours(hours);
            HttpContext.Current.Response.AppendCookie(cookie);
        }

        public static void Remove(string cookieName)
        {
            System.Web.HttpContext.Current.Response.Cookies[cookieName].Value = null;
            System.Web.HttpContext.Current.Response.Cookies[cookieName].Expires = DateTime.Now.AddDays(-10);

        }
    }
}
